﻿Imports System
Imports System.ComponentModel
Imports System.Workflow.ComponentModel

Namespace System.Workflow.ComponentModel.Design
    Friend NotInheritable Class ActivityBindNamePropertyDescriptor
        Inherits DynamicPropertyDescriptor
        ' Methods
        Public Sub New(ByVal context As ITypeDescriptorContext, ByVal realPropertyDescriptor As PropertyDescriptor)
            MyBase.New(context, realPropertyDescriptor)
            Me.context = context
        End Sub

        Public Overrides Function GetValue(ByVal component As Object) As Object
            Dim obj2 As Object = MyBase.GetValue(component)
            Dim str As String = [TryCast](obj2,String)
            If Not String.IsNullOrEmpty(str) Then
                Dim context As Activity = [TryCast](PropertyDescriptorUtils.GetComponent(Me.context),Activity)
                context = If((Not context Is Nothing), Helpers.ParseActivityForBind(context, str), Nothing)
                obj2 = If((Not context Is Nothing), context.QualifiedName, str)
            End If
            Return obj2
        End Function

        Public Overrides Sub SetValue(ByVal component As Object, ByVal value As Object)
            Dim str As String = [TryCast](value,String)
            If String.IsNullOrEmpty(str) Then
                Throw New InvalidOperationException(SR.GetString("Error_ActivityIdentifierCanNotBeEmpty"))
            End If
            Dim context As Activity = [TryCast](PropertyDescriptorUtils.GetComponent(Me.context),Activity)
            If ((Not context Is Nothing) AndAlso (Helpers.ParseActivityForBind(context, str) Is Nothing)) Then
                Throw New InvalidOperationException(SR.GetString("Error_InvalidActivityIdentifier", New Object() { str }))
            End If
            MyBase.SetValue(component, value)
        End Sub


        ' Fields
        Private context As ITypeDescriptorContext
    End Class
End Namespace

